package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import modelo.Usuario;
import util.ConnectionFactory;

public class DaoUsuario {
	private Connection conexao = ConnectionFactory.getConnection();
	private String sql = "";
	private PreparedStatement stm = null;

	public void inserirUsuario(Usuario user) throws SQLException {
		sql = "insert into usuario (email, nome, sobrenome) values(?,?,?)";

		stm = conexao.prepareStatement(sql);
		stm.setString(1, user.getEmail());
		stm.setString(2, user.getNome());
		stm.setString(3, user.getSobrenome());

		stm.execute();
	}

	public void atualizarUsuario(Usuario user) throws SQLException {
		sql = "update into usuario (email, nome, sobrenome) values(?,?,?)";

		stm = conexao.prepareStatement(sql);
		stm.setString(1, user.getEmail());
		stm.setString(2, user.getNome());
		stm.setString(3, user.getSobrenome());

		stm.executeQuery(sql);
	}

	public void removerUsuario(Usuario user) {

	}
	
	public void pesquisarUsuario(String id){
		
	}

	public List<Usuario> listarUsuario() throws SQLException {
		sql = "SELECT * FROM usuario";
		stm.execute();
		stm = conexao.prepareStatement(sql);
		
		ResultSet rs = stm.executeQuery(sql);
		Usuario user = new Usuario();
		List<Usuario> lista = new ArrayList<Usuario>();
		
		System.out.println(rs.getString("nome"));
		/*while(rs.next()){
			user.setNome(rs.getString("nome"));
			user.setSobrenome(rs.getString("sobrenome"));
			user.setEmail(rs.getString("email"));
			lista.add(user);
		}*/
		return lista;
}
}
